

/**
 * Memory.h: definitions for memory.c. memory.c is used to generate
 * the page tables used by freeGSD. This has the useful definitions
 * for that code to work.
 */

#ifndef __MEMORY
#  define __MEMORY

#  include <kernel.h>

extern unsigned int __memory;    // KBytes of memory.
extern struct __page_directory_entry *__pdir_table;  // Kernel page dir
extern struct __page_table_entry *__page_table;   // Kernel page table entrys

#  define __KERNEL_TEXT    0x00100000
#  define __KERNEL_BSTAK   0x00200000
#  define __KERNEL_TSTAK   0x00210000
#  define __KERNEL_DATA    0x00210000
#  define __KERNEL_PAGES   0x00300000
#  define __KERNEL_END     0x00700000

struct __page_directory_entry {

  unsigned char   flags;             /* Flags for the page table/dir.   */
  unsigned char   res:4;             /* Set to zero. Not used (yet).    */
  unsigned int    base_addr:20;      /* The address of the page table   */
                                     /* left shifted 12 bits (4KBytes). */

} __attribute__((packed));

struct __page_table_entry {

  unsigned char   flags;
  unsigned char   global:1;
  unsigned char   res:3;
  unsigned int    base_addr:20;

} __attribute__((packed));

#  define __PG_PRESENT     0x01
#  define __PG_READ_WRITE  0x02
#  define __PG_PRIVLIGE    0x04
#  define __PG_WRITE_THRU  0x08
#  define __PG_CACHE       0x10
#  define __PG_ACCESSED    0x20
#  define __PG_DIRTY       0x40
#  define __PG_INDEX       0x80

#  define __PGD_RESERVED   0x40
#  define __PGD_SIZE       0x80

void init_kernel_mem();
void __make_process_page_dir(void *addr);

void __make_kernel_page_dir();
void __make_kernel_page_table(char flags, void *base_addr,
			      struct __page_directory_entry dir);

void __write_page_dir_entry(unsigned int index, 
			    unsigned int base_addr, char flags);

void __set_page_global(struct __page_table_entry *);

unsigned int __use_pages(unsigned int addr);

extern void __flush_page_dir(void *addr);

#endif
